package com.library.entity;

import lombok.Data;
import lombok.NoArgsConstructor;

@Data
@NoArgsConstructor
public class Pagination {
    private int currentPage = 1;
    private int pageSize = 10;
    private int total = 0;
    private int maxPage;

    /// 计算最大页数
    public int getMaxPage() {
        this.maxPage = (int) Math.ceil((double) this.total / pageSize);
        return maxPage;
    }

    /// 设置当前页
    public Boolean setCurrentPage(int currentPage) {
        if (currentPage > 0 && currentPage <= maxPage) {
            this.currentPage = currentPage;
            return true;
        }
        return false;
    }

    /// 下一页
    public Boolean next() {
        if (currentPage < maxPage) {
            this.currentPage = currentPage + 1;
            return true;
        }
        return false;
    }

    /// 上一页
    public Boolean prev() {
        if (currentPage > 1) {
            this.currentPage = currentPage - 1;
            return true;
        }
        return false;
    }
}
